<template>
  <div>
    <el-form label-width="120px" :model="formData">
      <el-form-item label="Id">
        <el-input v-model="formData.id" disabled></el-input>
      </el-form-item>
      <el-form-item label="名称">
        <el-input v-model="formData.text"></el-input>
      </el-form-item>
      <el-form-item label="实现方式">
        <el-select v-model="formData.serviceType" placeholder="请选择" @change="changeServiceLabel">
          <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="serviceLabel" v-if="serviceLabel">
        <el-input v-model="formData.expression" ></el-input>
      </el-form-item>
<!--       <el-form-item>-->
<!--        <el-button type="primary" @click="onSubmit">保存</el-button>-->
<!--      </el-form-item>-->
    </el-form>
  </div>
</template>
<script>
export default {
  name: '',
  props: {
    nodeData: Object,
    lf: Object || String,
  },
  mounted() {
    const { properties, text,id} = this.$props.nodeData
    if (properties) {
      this.$data.formData = Object.assign({}, this.$data.formData, properties)
      if(properties.serviceType){
          this.options.forEach((item)=>{
            if(item.value==properties.serviceType){
              this.serviceLabel=item.label
            }
          })
      }
    }
    if (text && text.value) {
      this.$data.formData.text = text.value
    }
    if (id ) {
      this.$data.formData.id = id
    }

  },
  data () {
    return {
      serviceLabel: '',
      formData: {
          id:'',
          text:'',
          serviceType: '',
          expression: ''
        },
      options:[{
        value: '1',
        label: 'Java类'
      }, {
        value: '2',
        label: '委托表达式'
      }]
    }
  }, 
  methods: {
    save() {
      const { id } = this.$props.nodeData
      this.$props.lf.setProperties(id, {
        ...this.$data.formData
      });
      this.$props.lf.updateText(id, this.$data.formData.text);
      this.$emit('onClose')
    },
    changeServiceLabel(params){

      this.options.forEach((item)=>{
        if(item.value==params){
          this.serviceLabel=item.label
        }
      })

    }
  }
}
</script>
<style scoped>
</style>
